<template>
  <div class="header" :style="{'background-color':istourism?'#fb8d50':'#1874CD'}">
    <div class="logo fl"></div>
    <div class="logo_title">全国旅行社管理系统</div>
    <div class="showall">
      <div class="dropdown"><a :href='showInfo.unified_login_base_url' style="color:#ffffff;">总览</a></div>
      <div class="line"></div>
      <div class="dropdown dropdown-top-menu" style="color:#ffffff; cursor:pointer;"  @click="showTop = !showTop"><a href="javascript:;" style="color:#ffffff;">业务</a><i class="el-icon-caret-bottom el-icon--right"></i>
        <ul class="dropdown-menu dropdown-box" :style="{'background-color':istourism?'#fb8d50':'#1874CD'}" v-if="showTop">
          <li v-for="(item,index) in topMenus" :key="index">
            <div class="menu-li-title">{{item.name}}</div>
            <ul class="sub-menu">
              <li v-for="(citem,cindex) in item.list" :key="cindex"><a :href="citem.url">{{citem.name}}</a></li>
            </ul>
          </li>
        </ul>
      </div>
    </div>
    <div class="user-info">
      <!-- <div style="margin: 0;padding: 0;float: right;">
          <div class="menu-top-right">
                    <a href="" id="click-out"><i class=""></i>退出</a>
                    <a href="javascript:void(0);" style="cursor: default!important;"><i class="icon icon-menu-user"></i>邯郸（邯郸市旅游局）</a>
                </div>
                <div class="menu-bottom-right">
                        <a href="http://12301help.oss-cn-beijing.aliyuncs.com/2017/10/%E6%97%85%E6%B8%B8%E5%B1%80%E7%AB%AF%E6%93%8D%E4%BD%9C%E6%89%8B%E5%86%8C%EF%BC%88%E5%90%88%E8%AE%A2%EF%BC%8920170901.pdf" target="_blank">操作手册 |</a>
                    <a href="http://help.12301.cn/" target="_blank">在线帮助 |</a>
                    <a href="http://help.12301.cn/log-a-support-ticket/" target="_blank">提交问题 |</a>
                    <a href="javascript:void(0)" style="cursor: default!important;">热线电话：12301</a>
                </div>
      </div> -->
      <div class="top-menu">
                <div class="menu-top-right">
                    <a href="javascript:;" @click="logout"><i class="icon icon-menu-exit"></i>退出</a>
                    <a href="javascript:;" style="cursor: default!important;"><i class="icon icon-menu-user"></i>{{uname}}&nbsp;</a>
                </div>
                <div class="menu-bottom-right">
                    <a :href="helpUrl" target="_blank">操作手册 |</a>
                    <a href="http://help.12301.cn/" target="_blank">在线帮助 |</a>
                    <a href="http://help.12301.cn/log-a-support-ticket/" target="_blank">提交问题 |</a>
                    <a href="javascript:;" style="cursor: default!important;">热线电话：12301</a>
                </div>
            </div>
        <!-- <el-col :span="3">
          <a href="http://help.12301.cn/" class="dropdown-toggle" target="_blank" title="系统帮助">
            <i class="el-icon-question"></i>
          </a>
        </el-col>
        <el-col :span="3">
          <a href="http://help.12301.cn/log-a-support-ticket/" class="dropdown-toggle" title="提交问题" target="_blank">
            <i class="el-icon-message"></i>
          </a>
        </el-col>
        <el-col :span="10">
          <a href="javascript:void(0);" class="dropdown-toggle">
            <i class="report-icon-account"></i><span style="padding-left:10px;" v-text="userinfo.userName ? userinfo.userName : ''"></span>
          </a>
        </el-col>
        <el-col :span="6" style="text-align:" >
          <i class="report-icon-logout"></i><span style="margin-left:10px; center;cursor:pointer;" @click="logout">登出</span>
        </el-col> -->
    </div>
  </div>
</template>
<script>
import { mapGetters } from "vuex";

export default {
  computed: {
    ...mapGetters([
      "istourism",
      "userinfo",
      "sysinfo",
      "taPdfUrl",
      "govPdfUrl"
    ]),
    helpUrl() {
      return this.istourism ? this.taPdfUrl : this.govPdfUrl;
    },
    showInfo() {
      return this.sysinfo
        ? this.sysinfo.showInfo
        : {
            unified_login_base_url: "",
            menuUrl: "",
            type: 1
          };
    },
    uname() {
      return this.userinfo && this.userinfo.userName
        ? this.userinfo.userName
        : "";
    }
  },
  watch: {
    showInfo: function(newVal, oldVal) {
      this.getTopMenu(newVal);
    }
  },
  data() {
    return {
      topMenus: [],
      showTop: false
    };
  },
  methods: {
    logout() {
      this.$confirm(
        "<span style='font-size:16px;'>确定要登出吗？</span>",
        "提示",
        {
          showCancelButton: true,
          dangerouslyUseHTMLString: true,
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "success"
        }
      )
        .then(() => {
          let logouturl = "";
          if (this.istourism) {
            logouturl = "/ta/logout";
          } else {
            logouturl = "/gov/logout";
          }
          new Promise((resolve, reject) => {
            this.$http.fetchPost(logouturl, {}).then(
              response => {
                window.location.href = response.url;
              },
              response => {
                reject(response);
              }
            );
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    getTopMenu(newShowInfo) {
      if (newShowInfo) {
        let _this = this;
        const jsonpUrl = newShowInfo.menuUrl + "?type=" + newShowInfo.type;
        $.ajax({
          url: jsonpUrl,
          type: "get",
          async: false,
          dataType: "jsonp",
          jsonpCallback: "callback",
          success: function(data) {
            _this.topMenus = data;
          }
        });
      }
    }
  }
};
</script>
<style scoped>
.header {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  font-size: 20px;
  line-height: 60px;
  color: #fff;
}

.header .logo_title {
  float: left;
  width: 250px;
  text-align: center;
}

.user-info {
  position: relative;
  width: 22%;
  float: right;
  height: 60px;
  line-height: 60px;
  font-size: 14px;
  color: #fff;
}

.menu-top-right {
  font-size: 14px;
  color: #fff;
  padding-right: 10px;
  text-align: right;
  padding-top: 7px;
  float: right;
  line-height: 20px;
}
.menu-top-right a {
  color: #fff;
  float: right;
  font-weight: normal;
}

.menu-top-right .icon-menu-exit {
  display: inline-block;
  width: 25px;
  height: 18px;
  background: url(../assets/images/menu_exit.png) left center no-repeat;
  background-size: 18px 18px;
  float: left;
}
.menu-top-right .icon-menu-user {
  display: inline-block;
  width: 25px;
  height: 18px;
  background: url(../assets/images/menu_user.png) center center no-repeat;
  background-size: 18px 18px;
  float: left;
}

.menu-bottom-right {
  color: #fff;
  padding-right: 10px;
  clear: both;
  float: right;
}
.menu-bottom-right a {
  color: #fff;
  font-size: 12px;
  display: inline-block;
  line-height: 30px;
  float: left;
  padding-left: 3px;
}
.user-info .el-dropdown-link {
  position: relative;
  display: inline-block;
  padding-left: 50px;
  color: #fff;
  cursor: pointer;
  vertical-align: middle;
}

.user-info .user-logo {
  position: absolute;
  left: 0;
  top: 15px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.logo {
  width: 35px;
  height: 35px;
  background: url(../assets/images/logo.png) left center no-repeat;
  background-size: 100%;
  margin-top: 10px;
  margin-left: 30px;
  margin-right: -20px;
}

.fl {
  float: left;
  display: inline;
}

.dropdown-toggle {
  margin: 0px;
  color: #ffffff;
  padding: 17px 10px 12px 10px;
}

.showall {
  display: inline;
  font-size: 14px;
  height: auto;
  width: 20%;
}

.showall .line {
  width: 1px;
  height: 30px;
  border-left: 1px solid #eaeaea;
  display: inline-block;
  margin-bottom: -10px;
}

.showall .dropdown {
  display: inline;
  padding: 0px 20px;
}
.dropdown-top-menu {
  position: relative;
}
</style>
